package com.yu.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whyxzz.arcface.ArcFace;
import com.yu.crm.domain.pojo.CallerReservationPeople;
import com.yu.crm.mapper.CallerReservationPeopleMapper;
import com.yxzz.common.helper.DataHelpers;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * <p>
 * 预约用户表 服务实现类
 * </p>
 *
 * @author song
 * @since 2020-06-28
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CallerReservationPeopleService extends ServiceImpl<CallerReservationPeopleMapper, CallerReservationPeople> {

    public String isCaller(byte[] bytes, ArcFace arcFace) {
        QueryWrapper<CallerReservationPeople> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted",0);
        List<CallerReservationPeople> callerReservationPeopleList = baseMapper.selectList(queryWrapper);
        for (CallerReservationPeople callerReservationPeople:callerReservationPeopleList
             ) {
            if (arcFace.compareFaceFeature(bytes, callerReservationPeople.getCertificateEigen())) {
                return callerReservationPeople.getOpenId();
            }
        }
        return "";
    }

/*    public void addList(List<CallerReservationPeople> callerReservationPeopleList) {
        if (DataHelpers.isNotEmpty(callerReservationPeopleList) && callerReservationPeopleList.size()>0) {
            this.saveBatch(callerReservationPeopleList);
        }
    }*/

    public CallerReservationPeople getByOpenId(String openid) {
        QueryWrapper<CallerReservationPeople> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("open_id", openid);
        return baseMapper.selectOne(queryWrapper);
    }
}
